﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using VideoClassLibrary.Model;
using VideoClassLibrary.BusinessLogicLayer;

public partial class _courselistDest :AdminUserBase
{
    public string courseListHtml;
    public string usereListHtml;   
    V_adminUser currentAdminUser;
    CourselistDestModule CDM = new CourselistDestModule();

    protected void Page_Load(object sender, EventArgs e)
    {
        currentAdminUser = (V_adminUser)Session["currentAdminUser"];

        if (IsPostBack == false)
        {
            CreateForm();
        }
        

    }

    private void CreateForm()
    {
        TrainClassModule TCM = new TrainClassModule();
        DataSet ds = TCM.GetTrainclassListByWhere(this.SchoolID, " and IsPublish=1 ");
        courseListHtml = "";
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
    //        
    //
    //
    //
    //
            courseListHtml += "<table style='width:100%;color:#336699; border-left: 1px solid #c5d4db; border-top: 1px solid #c5d4db; font-family:\"微软雅黑\"; height: 20px;width: 700px;'><tr>";
            courseListHtml += "<td class='ta2'><input name=\"trainClassIdchk\" type=\"checkbox\" value=\""+ dr["ID"].ToString()+ "\"/>"+"</td>";
            courseListHtml += "<td class='ta2 tag'>培训班名称:</td>" + "<td class='ta2 tag'>" + dr["vtc_name"].ToString() +"</td>";
            courseListHtml += "<td class='ta2 tag'>培训班开始日期:</td>" + "<td class='ta2 tag'>" + DateTime.Parse(dr["vtc_starDate"].ToString()).ToString("yyyy-MM-dd") +"</td>";
            courseListHtml += "<td class='ta2 tag'>培训班结束日期:</td>" + "<td class='ta2 tag'>" + DateTime.Parse(dr["vtc_enddate"].ToString()).ToString("yyyy-MM-dd") +"</td>";
            courseListHtml += "</tr></table>";
        }

        UserModule userModule = new UserModule();
        ds = userModule.GetUserListByWhere(" and IsAvailable=1 ", this.SchoolID);
        usereListHtml = "";
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            usereListHtml += "<table style='width:100%;color:#336699; border-left: 1px solid #c5d4db; border-top: 1px solid #c5d4db; font-family:\"微软雅黑\"; height: 20px;width: 1200px;'><tr>";
            usereListHtml +="<td class='ta2'><input name=\"UserIDchk\" type=\"checkbox\" value=\""+dr["id"].ToString()+"\"/>"+"</td>";
            usereListHtml +="<td class='ta2 tag'>真实姓名:</td>"+"<td class='ta2 tag'>"+ dr["vu_realname"].ToString()+"</td>";
            usereListHtml +="<td class='ta2 tag'>登录名:</td>"+"<td class='ta2 tag'>"+ dr["vu_loginname"].ToString()+"</td>";
            usereListHtml +="<td class='ta2 tag'>联系方式:</td>"+"<td class='ta2 tag'>"+ dr["VU_mobile"].ToString()+"</td>";
            usereListHtml +="<td class='ta2 tag'>邮箱:</td>"+"<td class='ta2 tag'>"+dr["vu_email"].ToString()+"</td>";
            usereListHtml +="</tr></table>";
        }

    }

    private void SaveCLD()
    {
        //V_courselistDest V_CLD;

        if (Request.Form["trainClassIdchk"] == null || Request.Form["UserIDchk"] == null)
        {
            Response.Write("<script>alert(\"培训班和学员都不能为空！\");history.go(-1);</script>");

            return;
        }
        string trainClass = Request.Form["trainClassIdchk"].ToString();
        string UserIDlist = Request.Form["UserIDchk"].ToString();

        
        foreach (string tid in trainClass.Split(','))
        {

            CDM.AddCourselistDest(currentAdminUser.SchoolID.ToString(), UserIDlist, tid);
        }
        Response.Redirect("courselistDestbrowser.aspx");
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        SaveCLD();
    }
}
